import axios from './axios'
import qs from 'qs'
import { baseUrl } from '@/config/config'
// 获取商店列表
export const shopGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/shops',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增店铺
export const shopPost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/shop',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改店铺
export const shopPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/shop/' + params.id,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 用户删除
export const shopDelete = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/shop/' + params.id,
      method: 'Delete',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取商店列表
export const adGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/ads',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增店铺
export const adPost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/ad',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改店铺
export const adPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/ad/' + params.id,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 用户删除
export const adDelete = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/ad/' + params.id,
      method: 'Delete',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取分类列表
export const categoryGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/categorys',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增分类
export const categoryPost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/category',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改分类
export const categoryPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/category/' + params.id,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 删除分类
export const categoryDelete = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/category/' + params.id,
      method: 'Delete',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取产品列表
export const productGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/products',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增产品
export const productPost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/product',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改产品
export const productPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/product/' + params.id,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 删除产品
export const productDelete = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/product/' + params.id,
      method: 'Delete',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取订单列表
export const orderGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/shop/orders',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 订单退款
export const orderPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/order/' + params.id,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改订单状态
export const orderStatusPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/order/' + params.id + '/' + params.status,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改订单状态
export const orderPostnoPut = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/order/' + params.id + '/postno/' + params.post_no,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 删除订单
export const orderDelete = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/order/' + params.id + '/' + params.del,
      method: 'Delete',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
